<g:set var="PUUID" value="${Math.round(Math.random()*9999999)}" />
<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="${request.getContextPath()}/js/public-head.js"></script>
</head>
<body>
<div class="layui-row">
    <div class="layui-card">
        <div class="layui-card-body">
            <form   class="layui-form" method="post"  >
                <input type="hidden" name="boardId" value="${boardId}">
                <div class="layui-form-item">
                    <label class="layui-form-label">节点</label>
                    <div class="layui-input-block">
                        <g:select name="nodeNo" from="${eqpList}"   lay-search="" lay-filter="nodeNo"
                                  optionKey="NODE_NO" optionValue="NODE_NAME" value=""
                                  noSelection="${['': '']}" />

                    </div>
                    <input type="hidden"  name="name"  class="layui-input"  value="">
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input"  name="nodeDesc" value="" placeholder="鼠标移入可显示信息">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">Action</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input"  name="actionUrl" value=""
                               placeholder="超链接:目标URL?参数名,系统自动拼接当前节点ID">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">节点区域</label>
                    <div class="layui-input-block">
                        <g:select name="groupNo" from="${appBordGroup}"   lay-search=""
                                  optionKey="groupNo" optionValue="groupName" value=""
                                  noSelection="${['': '']}" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">初始状态</label>
                    <div class="layui-input-block">
                        <g:select name="typeNo" from="${appBordType}"   lay-search="" lay-verify="required"
                                  optionKey="typeNo" optionValue="typeName" value=""  
                             />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">链接节点</label>
                    <div class="layui-input-block">
                        <g:select from="${relaList}" lay-search=""
                                  name="relaNodeNo" id="relaNodeNo"
                                  optionKey="nodeNo" optionValue="nodeName"
                                  value="" noSelection="${['': '']}"
                        ></g:select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">链接线</label>
                    <div class="layui-input-block">
                        <g:select name="relaLine" from="${relaLineList}" data-toggle="selectpicker" lay-search=""
                                  optionKey="value" optionValue="label" value=""
                                  data-width="120"
                                  noSelection="${['': '']}"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">初始报警</label>
                    <div class="layui-input-block">
                        <g:select name="alarmNo" from="${appBordAlarm}"
                                  optionKey="alarmNo" optionValue="alarmName" value="" lay-search=""
                                  data-width="120"
                                  noSelection="['': '']"/>

                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">报警信息</label>
                    <div class="layui-input-block">
                        <input type="text" name="alarmInfo" value=""  class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">节点图标</label>
                    <div class="layui-input-block">
                         <input type="radio" name="nodeImg"   value="" title="纯色块"   checked />
                        <g:each in="${iconList}" var="item" status="i">
                            <input type="radio" name="nodeImg"  value="${item}"
                                   title="<img src='${request.getContextPath()}/${item}'>"
                            />
                        </g:each>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <button  class="layui-btn" lay-submit="*"  lay-filter="*">保存</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

</body>


<script type="text/javascript">
    layui.config({
        base: basePath+'/layui/lay/modules/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use([ 'table','form','laydate'], function(){
        var $ = layui.$
        var form = layui.form

        form.on("submit(*)",function(obj){
            var url = "${request.getContextPath()}/appBordNodeMonitor/update";
            $.getJSON(url,obj.field,function(rst){
                if(rst.statusCode == 200){
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭   ;
                }else{
                    layer.alert(rst.message,{icon:2})
                }
            })
            return false
        })

        form.on('select(nodeNo)', function(data){
           $("input[name='name']").val($("dd[lay-value="+data.value+"]").html())
        });
    })
</script>


<script type="text/javascript">
    var groupMap = {
    <g:each in="${appBordGroup}" var="g">
    "${g.groupNo}": "${g.groupName}",
    </g:each>
    }


    function fn${PUUID}(value,domId){
        var url = "${request.getContextPath()}/appBordNodeMonitor/nodeOption";
        var domObj = $.CurrentDialog.find(domId);
        var _this = $.CurrentDialog;
        $.ajax(url,{
            data:{nodeNo:value},
            dataType:"json",
            async:false,
            success: function (jsonData) {
                var relaNodes = jsonData.relaNodes;
                var nodeInstance = jsonData.nodeInstance;
                domObj.empty();
                domObj.append("<option value=''>-可选-</option>")
                $.each(relaNodes,function(index,item){
                    var groupNo = item.groupNo? groupMap[item.groupNo]+'-' :'';
                    domObj.append("<option value="+item.nodeNo+">"+ groupNo + item.nodeName +"</option>");
                });
                domObj.selectpicker('refresh');

                _this.find("input[name=name]").val( nodeInstance==null?'': nodeInstance.nodeName)
                _this.find("input[name=nodeDesc]").val( nodeInstance==null?'': nodeInstance.nodeDesc)
                _this.find("select[name=groupNo]").selectpicker('val', nodeInstance==null?'':nodeInstance.groupNo)
                _this.find("select[name=typeNo]").selectpicker('val', nodeInstance==null?'':nodeInstance.typeNo)
                _this.find("select[name=relaNodeNo]").selectpicker('val', nodeInstance==null?'':nodeInstance.relaNodeNo)
                _this.find("select[name=relaLine]").selectpicker('val', nodeInstance==null?'':nodeInstance.relaLine)
                _this.find("select[name=alarmNo]").selectpicker('val', nodeInstance==null?'':nodeInstance.alarmNo)
                _this.find("input[name=alarmInfo]").val( nodeInstance==null?'':nodeInstance.alarmInfo)
                _this.find("input[name=nodeImg]").each(function(index,icheck){
                    if(nodeInstance==null){
                        _this.find("input[name=nodeImg]:first").iCheck('check');
                        return
                    }
                    if( icheck.value == nodeInstance.nodeImg ){
                        $(icheck).iCheck('check');
                        return;
                    }
                })

            }
        })
    }

</script>
